package com.studentapp.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.studentapp.R;
import com.studentapp.fragment.ClassmateFragment;
import com.studentapp.fragment.CommentFragment;
import com.studentapp.fragment.NewsFragment;
import com.studentapp.fragment.NoticeFragment;
import com.studentapp.fragment.StudentFragment;

public class IndexActivity extends AppCompatActivity implements View.OnClickListener {

    private FrameLayout fragment;
    private TextView classmate;
    private TextView comment;
    private TextView news;
    private TextView notice;
    private TextView student;
    FragmentManager fm;
    FragmentTransaction ft;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);
        initView();
    }

    private void initView() {
        fragment = (FrameLayout) findViewById(R.id.fragment);
        classmate = (TextView) findViewById(R.id.classmate);
        comment = (TextView) findViewById(R.id.comment);
        news = (TextView) findViewById(R.id.news);
        notice = (TextView) findViewById(R.id.notice);
        student = (TextView) findViewById(R.id.student);

        classmate.setOnClickListener(this);
        comment.setOnClickListener(this);
        news.setOnClickListener(this);
        notice.setOnClickListener(this);
        student.setOnClickListener(this);

         fm = getSupportFragmentManager();
         ft = fm.beginTransaction();
        ft.replace(R.id.fragment,new NewsFragment());
        ft.commit();
    }

    @Override
    public void onClick(View v) {
        fm = getSupportFragmentManager();
        ft = fm.beginTransaction();
        switch (v.getId()) {

            case R.id.classmate:
                ft.replace(R.id.fragment,new ClassmateFragment());
                ft.commit();
                break;
            case R.id.comment:
                ft.replace(R.id.fragment,new CommentFragment());
                ft.commit();
                break;
            case R.id.news:
                ft.replace(R.id.fragment,new NewsFragment());
                ft.commit();
                break;
            case R.id.notice:
                ft.replace(R.id.fragment,new NoticeFragment());
                ft.commit();
                break;
            case R.id.student:
                ft.replace(R.id.fragment,new StudentFragment());
                ft.commit();
                break;
        }
    }
}
